home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / NLEqn.h < prev    next >
C/C++ Source or Header  |  1996-03-03  |  3KB  |  141 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_NLEqn_h)
  24. #define octave_NLEqn_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include <cfloat>
  31. #include <cmath>
  32.  
  33. #include "dColVector.h"
  34. #include "NLFunc.h"
  35.  
  36. class
  37. NLEqn_options
  38. {
  39. public:
  40.  
  41.   NLEqn_options (void)
  42.     : x_tolerance (::sqrt (DBL_EPSILON)) { }
  43.  
  44.   NLEqn_options (const NLEqn_options& opt)
  45.     : x_tolerance (opt.x_tolerance) { }
  46.  
  47.   NLEqn_options& operator = (const NLEqn_options& opt)
  48.     {
  49.       if (this != &opt)
  50.     x_tolerance = opt.x_tolerance;
  51.  
  52.       return *this;
  53.     }
  54.  
  55.   ~NLEqn_options (void) { }
  56.  
  57.   void set_default_options (void) { x_tolerance = ::sqrt (DBL_EPSILON); }
  58.  
  59.   void set_options (const NLEqn_options& opt)
  60.     { x_tolerance = opt.x_tolerance; }
  61.  
  62.   void set_tolerance (double val)
  63.     { x_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); }
  64.  
  65.   double tolerance (void) { return x_tolerance; }
  66.  
  67. private:
  68.  
  69.   double x_tolerance;
  70. };
  71.  
  72. class
  73. NLEqn : public NLFunc, public NLEqn_options
  74. {
  75. public:
  76.  
  77.   NLEqn (void)
  78.     : NLFunc (), NLEqn_options (), x () { }
  79.  
  80.   NLEqn (const ColumnVector& xx, const NLFunc f) 
  81.     : NLFunc (f), NLEqn_options (), x (xx) { }
  82.  
  83.   NLEqn (const NLEqn& a)
  84.     : NLFunc (a.fun, a.jac), NLEqn_options (), x (a.x) { }
  85.  
  86.   NLEqn& operator = (const NLEqn& a)
  87.     {
  88.       if (this != &a)
  89.     {
  90.       NLFunc::operator = (a);
  91.       NLEqn_options::operator = (a);
  92.  
  93.       x = a.x;
  94.     }
  95.       return *this;
  96.     }
  97.  
  98.   ~NLEqn (void) { }
  99.  
  100.   void set_states (const ColumnVector& xx) { x = xx; }
  101.  
  102.   ColumnVector states (void) const { return x; }
  103.  
  104.   int size (void) const { return x.capacity (); }
  105.  
  106.   ColumnVector solve (void)
  107.     {
  108.       int info;
  109.       return solve (info);
  110.     }
  111.  
  112.   ColumnVector solve (const ColumnVector& xvec)
  113.     {
  114.       set_states (xvec);
  115.       int info;
  116.       return solve (info);
  117.     }
  118.  
  119.   ColumnVector solve (const ColumnVector& xvec, int& info)
  120.     {
  121.       set_states (xvec);
  122.       return solve (info);
  123.     }
  124.  
  125.   ColumnVector solve (int& info);
  126.  
  127.  private:
  128.  
  129.   ColumnVector x;
  130.  
  131.   void error (const char* msg);
  132. };
  133.  
  134. #endif
  135.  
  136. /*
  137. ;;; Local Variables: ***
  138. ;;; mode: C++ ***
  139. ;;; End: ***
  140. */
  141.